<?php


namespace app\api\controller\v1;


use app\common\Token;
use app\api\model\DouBanTop;
use app\api\model\MovieItem;
use app\api\Validate\SearchMovieValidate;
use app\BaseController;
use think\App;
use think\db\exception\DbException;
use think\response\Json;

class Movie extends BaseController
{
    /**
     * 获取电影列表接口
     * {"page":1, "limit":10}
     * @return Json
     * @throws DbException
     */
    public function movieList() {
        Token::checkToken($this->request);
        $re = (new MovieItem())->toPaginate($this->request->post());
        return successJson($re);
    }

    /**
     * {"translatedName":"八","
     * 搜索电影接口movieName":"","page":1,"limit":10}
     * @return Json
     * @throws DbException
     */
    public function searchMovieByName() {
        Token::checkToken($this->request);
        $param = (new SearchMovieValidate()) -> validateParam();
        $re = (new MovieItem())->searchMovie($param);
        return successJson($re);
    }

    /**
     * 获取豆瓣Top250电影
     * @return Json
     * @throws DbException
     */
    public function douBanTop() {
//        Token::checkToken($this->request);
        $re = (new DouBanTop())->toPaginate($this->request->post());
        return successJson($re);
    }
}